package com.balabala.gym_goods.controller.app;

import com.balabala.goods.pojo.dto.CartItemDTO;
import com.balabala.gym_goods.service.CartService;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author 何涛
 * @Date: 2023/05/07/ 16:17
 * @description 购物车控制器
 */
@RestController
@RequestMapping("/app/cart")
@Slf4j
@Api(tags = "购物车前台接口")
@CrossOrigin
public class CartController {
    @Autowired
    CartService cartService;
    @ApiOperation("添加商品到购物车")
    @PostMapping("/addSkuToCart")
    public Result addSkuToCart(@RequestParam Long skuId)
    {
        log.info("添加商品到购物车");
        return Result.judge(cartService.addSkuToCart(skuId));
    }

    @ApiOperation("查看用户购物车")
    @GetMapping("/getUserCart")
    public Result getUserCart()
    {
        log.info("查看用户购物车");
        return Result.ok(cartService.getUserCart());
    }

    @ApiOperation("清空购物车")
    @PutMapping("/clearCart")
    public Result clearCart()
    {
        log.info("清空购物车");

        return Result.judge(cartService.clearCart());
    }

    @ApiOperation("更新购物车商品")
    @PutMapping("/updateCart")
    public Result updateCart(@RequestBody CartItemDTO cartItemDTO)
    {
        log.info("更新购物车商品");
        return Result.judge(cartService.updateCart(cartItemDTO));
    }

    @ApiOperation("删除购物车商品")
    @PutMapping("/deleteCartSku")
    public Result deleteCartSku(@RequestParam Long skuId)
    {
        log.info("删除购物车商品");
        return Result.judge(cartService.deleteCartSku(skuId));
    }

    @ApiOperation("全选/全不选操作购物车商品")
    @PutMapping("/isCheckAllSku")
    public Result isCheckAllSku(@RequestParam Boolean isCheckAll)
    {
        log.info("全选/全部选购物车商品");

        return Result.judge(cartService.checkAllOrAllCancel(isCheckAll));
    }

    @ApiOperation("删除已勾选购物车商品")
    @DeleteMapping("deleteCartCheckSkus")
    public Result deleteCartCheckSkus(List<Long> skuIds)
    {
        log.info("删除已勾选购物车商品");

        return Result.judge(cartService.deleteCheckCartSkus(skuIds));
    }

}
